package examples 
{
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import pure.engine.core.IVisible;
	import pure.engine.model.Entity;
	import pure.engine.events.InteractEvent;
	import pure.engine.model.AnimeRenderer;
	import pure.engine.model.IAnime;
	import pure.engine.model.IText;
	import pure.engine.world.GameWorld;
	/**
	 * ...
	 * @author Pure
	 */
public class SimpleWorld extends GameWorld 
{
	
	public function SimpleWorld() 
	{
		super(40, 30);
	}
	
	public var m_entity:Entity;
	public var m_renderer:IAnime;
	public var m_txt:IText;
	
	override public function enter():void
	{

		//m_entity = this.createFinalEntity('PlatformBoy', 200, 100);

		var l:int = 300;
		
		while (--l > -1)
		{
			m_entity = this.createSimpleEntity(100);
			if (Math.random() > 0.5) 
			{
				m_entity.interactive = false;
				m_entity.addFilter(new GlowFilter(0xFF3300, 0.8))
			}
			m_entity.move(Math.random() * 990 + 20 , Math.random() * 570 + 20);
			m_renderer = m_entity.createAnimeRenderer('colonist_32_32','p');
			m_renderer.play('right_run', null, true)
			
			m_txt = m_entity.createTextRenderer('分裂机器', 0, -30,2);
			//m_txt = m_entity.createTextRenderer('xxx', 0, -30);
			m_txt.color = 0xffffff;
			m_txt.setBackground(0x33dd33,0.5,4,1)
			m_txt.size = 12;
			m_txt.filters = [new GlowFilter(0,0.8,2,2,6)]
			//m_renderer.alpha = 0.5;
			//m_renderer.rotation = 30
			m_renderer.addEventListener(InteractEvent.PRESS, onPress);
			m_renderer.addEventListener(InteractEvent.OVER, onOver);
			m_renderer.addEventListener(InteractEvent.LEAVE, onLeave);
			m_renderer.addEventListener(InteractEvent.RELEASE, onRelease );
			m_renderer.addEventListener(InteractEvent.CLICK, onClick);
			
			m_txt.addEventListener(InteractEvent.OVER, onOver2);
			m_txt.addEventListener(InteractEvent.LEAVE, onLeave2);
			//m_renderer.addEventListener(InteractEvent.PRESS, onPress2);
		}
	
		//this.addEventListener(InteractEvent.PRESS, onPress3);
		//m_soul.addEntity(m_entity,'player');
		//
		//m_renderer = m_entity.headRenderer as AnimeRenderer;
		//m_rendererT = m_entity.tailRenderer as IText;
	}
	
	override public function exit():void
	{
		
	}
	
	
	
	
	private function onPress(e:InteractEvent):void
	{
		var A:IAnime = e.target as IAnime
		A.scaleX = A.scaleY = (A.scaleX == 1) ? 2 : 1;
		
		//(e.target as IAnime).visible = false;
	}
	private function onOver(e:InteractEvent):void
	{
		trace(e.type);
		
		(e.target as IAnime).pause();
		(e.target as IAnime).alpha = 0.5;
		//(e.target as IAnime).rotation = 30;
		//(e.target as IAnime).addFilter(new GlowFilter(0xffee33, 0.9, 19, 19,21))
		//(e.target as IAnime).section = 'gunner_40_32'
	}
	private function onLeave(e:InteractEvent):void
	{
		trace(e.type);
		
		(e.target as IAnime).resume();
		(e.target as IAnime).alpha = 1;
		//(e.target as IAnime).clearFilter();
		//(e.target as IAnime).section = 'colonist_32_32';
	}
	private function onRelease(e:InteractEvent):void
	{
		trace(e.type);
	}
	private function onClick(e:InteractEvent):void
	{
		//(e.target as IAnime).visible = false;
	}
	
	private function onOver2(e:InteractEvent):void
	{
		trace(e.type);
		
		(e.target as IText).color = 0xff3333;
		//(e.target as IAnime).section = 'gunner_40_32'
	}
	private function onLeave2(e:InteractEvent):void
	{
		trace(e.type);
		
		(e.target as IText).color = 0xffffff;
	}
}

}